#--
# Copyright (c) 2007 Maximilian Ott
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#++
# == Schema Information
# Schema version: 30
#
# Table name: users
#
#  id           :integer(10)   not null, primary key
#  login        :string(40)    default(""), not null
#  name         :string(128)   default(""), not null
#  admin        :integer(1)    default(0), not null
#  activated    :integer(1)    default(0), not null
#  email        :string(80)    default(""), not null
#  cypher       :text          default(""), not null
#  salt         :string(40)    default(""), not null
#  token        :string(10)    default(""), not null
#  token_expiry :timestamp     
#  created_on   :timestamp     
#  updated_on   :timestamp     
#  lock_version :integer(11)   default(0), not null
#  is_approver  :boolean(1)    
#

#
# This class contains all the user related specializations for 
# this application.
#

require 'ldap_user'

class User < LdapUser
  
  @@host = 'ldap.nicta.net'
  @@port = 389
  @@auth_user = "CN=LDAP Lookup,OU=Services,OU=Users,OU=NICTA,DC=in,DC=nicta,DC=com,DC=au"
  @@auth_pw = "IDUl36ey"
  @@base = 'dc=in,dc=nicta,dc=com,dc=au'

  # Create a default user
  #
  def self.bootstrap
    return if self.count > 0
    
    u = self.new
    Thread.current[:session] = {}
    self.current = u
    
    u.login = 'admin'
    u.email = 'admin@acme.com'
    u.name = 'Mr. Admin'
    u.admin = 1
    u.is_local = 1
    u.reset_password 'admin'
    u.save
  end
  
end
